//
//  NSAttributedString+Hyperlink.swift
//  OneMeeting
//
//  Created by zhangheng on 2019/8/16.
//  Copyright © 2019 www.zhangheng.com. All rights reserved.
//

import Foundation

extension NSAttributedString {
    class func hyperlinkFromString(inString:String,textColor:NSColor?=nil,aURL:URL?=nil) -> NSAttributedString {
        let newColor = (textColor != nil) ? textColor:NSColor.blue
        let attrString = NSMutableAttributedString.init(string: inString)
        let range = NSRange.init(location: 0, length: inString.count)
        attrString.beginEditing()
        attrString.addAttribute(NSAttributedString.Key.foregroundColor, value: newColor!, range: range)
        if let _ = aURL  {
            attrString.addAttribute(NSAttributedString.Key.link, value: aURL!, range: range)
        }
       
        attrString.addAttribute(NSAttributedString.Key.underlineStyle, value: NSUnderlineStyle.single.rawValue, range: range)
        attrString.endEditing()
        
        return attrString
    }
}
